package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.EventListData;
import com.lzx.iteam.util.DateUtil;
import com.lzx.iteam.util.StringUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mac on 15-7-8.
 */
public class DraftAdapter extends BaseAdapter {

    private List<EventListData> mList;
    private Context mContext;

    public DraftAdapter(List<EventListData> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder holder;
        if (view == null){
            holder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.draft_item_layout,null);
            holder.type = (TextView) view.findViewById(R.id.draft_item_type);
            holder.time = (TextView) view.findViewById(R.id.draft_item_time);
            holder.content = (TextView) view.findViewById(R.id.draft_item_content);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }

        EventListData eventData = mList.get(i);
        if (StringUtil.isEmpty(eventData.getEventTitle())){
            holder.type.setText(eventData.getEventName());
        }else{
            holder.type.setText(eventData.getEventTitle());
        }
        String content = eventData.getContent1();
        if (!StringUtil.isEmpty(content)){
            if ("8".equals(eventData.getEventType())){
                String[] votes = content.toString().split(",");
                StringBuilder vote = new StringBuilder();
                for (int j = 0; j < votes.length; j++) {
                    vote.append("选项"+(char)(65+j) +":"+votes[j]).append("  ");
                }
                holder.content.setText(vote.toString());
            }else{
                holder.content.setText(content);
            }
        }else{
            holder.content.setText("内容空");
        }
        holder.time.setText(DateUtil.getChatTime(Long.parseLong(eventData.getUpdateTime())));

        return view;
    }

    class ViewHolder{
        TextView type;
        TextView content;
        TextView time;
    }
}
